import { sify, tify } from 'chinese-conv'


/**
 * 简体转繁体
 * @param { string } text 
 * @returns 
 */
export function traditionalized(text: string) {
  if (!text) return text
  return tify(text)
}

/**
 * 繁体转简体
 * @param { string } text 
 * @returns 
 */
export function simplized(text: string) {
  if (!text) return text
  return sify(text)
}

function hasTraditional(text: string) {
  return text !== tify(text)
}

function hasSimplified(text: string) {
  return text !== sify(text)
}

/**
 * 简繁体自动转换
 * @param { string } text 
 * @returns 
 */
export function convert(text: string) {
  if (!text) return text
  const isTrad = hasTraditional(text)
  const isSimp = hasSimplified(text)
  if (isSimp && !isTrad) return traditionalized(text)
  if (isTrad && !isSimp) return simplized(text)
  return text
}